<?php
namespace app\model;
use app\model\UserOrder as ModelUserOrder;
use app\model\SysSetting as ModelSysSetting;
use think\Db;

class StationInfo extends LoginCommon
{
    protected static $obj;

    public function _initialize()
    {
        parent::_initialize();
        $this->db_name = 'station_info';
    }

    /**
     * 类入口
     * @return StationInfo
     */
    public static function getInstance()
    {
        if (is_null(self::$obj))
            self::$obj = new self();
        return self::$obj;
    }

    /**
     * 获取站点首页信息
     */
    public function getStationInfoList($arr_where,$int_first_row,$int_list_rows,$sort){
        $data = Db::name($this->db_name)
            ->where($arr_where)
            ->field('station_info.id,station_info.station_number,station_info.name,station_info.level,station_info.gmt_create as gmtCreate,station_info.state')
            ->limit($int_first_row,$int_list_rows)
            ->order("station_info.gmt_create $sort")
            ->select();
        return $data;
    }
    /*
    * 返回站点分佣
    */
    public function getCommission($mapId,$orderId){
        //获取订单信息
        $orderInfo = ModelUserOrder::getInstance()->toFind(['order_id'=>$orderId]);
        //获取快递员分佣类型
        $commissionType = $this->toValue(['id'=>$mapId],'commission_type');
        //添加快递员分佣
        if ($commissionType == 1){
            $commission = ModelSysSetting::getInstance()->stationCharges($commissionType);
        }elseif($commissionType == 2){
            $commission = ModelSysSetting::getInstance()->stationCharges($commissionType)*$orderInfo['order_amount']/100;
        }
        return $commission;
    }

}
